/*
 * Copyright (c) 2025, 廖树财, <study_2030@163.com>
 *
 * PEE2.0-YCYW-HY is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *         http://license.coscl.org.cn/MulanPSL2     
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

#pragma once
#include "define.h"
#include "JsonParser.h"
#include "zlog.h"
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <time.h>
#include <pwd.h>
#include <grp.h>
#include <dirent.h>
#include <upload.h>

extern char *LOGIN_USER;
extern char *LOGIN_PASSWORD;

typedef struct IOTA_DICTIONARY_PARAM
{
    char *path;
    char *fileName;
} IOTA_DICTIONARY_PARAM;

typedef struct IOTA_DICTIONARY_FILE_PARAM
{
    char *file;
} IOTA_DICTIONARY_FILE_PARAM;

typedef struct IOTA_DICTIONARY_COPY_PARAM
{
    char *srcpath;
    char *descpath;
    int isfile;
} IOTA_DICTIONARY_COPY_PARAM;

typedef struct IOTA_DICTIONARY_GETDICSIZE_PARAM
{
    char *path;
} IOTA_DICTIONARY_GETDICSIZE_PARAM;

typedef struct IOTA_DICTIONARY_DOWNLOAD_PARAM
{
    char *fileId;
    char *filename;
    int size;
    char *digestAlgorithm;
    char *digest;
    char *fileLink;
} IOTA_DICTIONARY_DOWNLOAD_PARAM;

typedef struct IOTA_DICTIONARY_INFO
{
    char filename[255];
    char user[40];
    char group[40];
    size_t size;
    char permission[11];
    char updatetime[64];
    char type[20];
} IOTA_DICTIONARY_INFO;

typedef struct IOTA_DICTIONARY_SIZE
{
    char path[255];
    char size[32];
} IOTA_DICTIONARY_SIZE;

typedef struct IOTA_DICTIONARY_PROGRESS
{
    char speed[32];    // 单位为kb/s
    long total;        // 总大小 单位为kb
    long now;          // 已下载大小 单位为kb
    long time;         // 剩余时间 单位为s
    char filename[200] // 文件名
} IOTA_DICTIONARY_PROGRESS;

typedef struct IOTA_DICTIONARY_BREAK_PARAM
{
    char *filename;
} IOTA_DICTIONARY_BREAK_PARAM;

bool send_progress_V2(int code, int progress, ST_IOTA_LOG_RES *progressDecs);

bool JsonToStruct_GetDictionaryTree(char *pcJson, ST_IOTA_LOG *pcStatusDecs);

bool JsonToStruct_UploadFiles(char *pcJson, ST_IOTA_LOG *pcStatusDecs);

bool JsonToStruct_CopyFile(char *pcJson, ST_IOTA_LOG *pcStatusDecs);

bool JsonToStruct_Break(char *pcJson, ST_IOTA_LOG *pcStatusDecs);

bool StructToJson_GetDictionaryTree(char **pcJson, ST_IOTA_LOG_RES *pcStatusDecs, int count);

bool StructToJson_GetDictionarySize(char **pcJson, ST_IOTA_LOG_RES *pcStatusDecs);

int get_file_info(const char *path, IOTA_DICTIONARY_INFO *file);

int dictionary_tree(char *pJson);

int dictionary_upload(char *pcJson);

int dictionary_file_download(char *arg);

int dictionary_download_pthread(char *pcJson);

int dictionary_download(char *pcJson);

int dictionary_copy(char *pcJson);

int dictionary_GetDicSize(char *pcJson);

int dictionary_break(char *pcJson, int action);

int dictionary_commond(char *pcJson);

int dictionary_delete(char *pcJson);
